package com.factory.dao;

import com.factory.entity.SalaryRecord;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

public interface SalaryRecordDao {

    // 插入工资记录
    @Insert("INSERT INTO salary_record(emp_id, base_salary, bonus, deduction, total_salary, salary_month, pay_date) " +
            "VALUES(#{empId}, #{baseSalary}, #{bonus}, #{deduction}, #{totalSalary}, #{salaryMonth}, #{payDate})")
    @Options(useGeneratedKeys = true, keyProperty = "recordId")
    int insertSalaryRecord(SalaryRecord salaryRecord);

    // 根据ID删除工资记录
    @Delete("DELETE FROM salary_record WHERE record_id = #{recordId}")
    int deleteSalaryRecord(Integer recordId);

    // 更新工资记录
    @Update("UPDATE salary_record SET base_salary=#{baseSalary}, bonus=#{bonus}, " +
            "deduction=#{deduction}, total_salary=#{totalSalary}, " +
            "salary_month=#{salaryMonth}, pay_date=#{payDate} WHERE record_id=#{recordId}")
    int updateSalaryRecord(SalaryRecord salaryRecord);

    // 根据ID查询工资记录
    @Select("SELECT * FROM salary_record WHERE record_id = #{recordId}")
    SalaryRecord selectSalaryRecordById(Integer recordId);

    // 查询所有工资记录
    @Select("SELECT * FROM salary_record")
    List<SalaryRecord> selectAllSalaryRecords();

    // 根据员工ID查询工资记录
    @Select("SELECT * FROM salary_record WHERE emp_id = #{empId}")
    List<SalaryRecord> selectSalaryRecordsByEmpId(Integer empId);

    // 根据月份查询工资记录
    @Select("SELECT * FROM salary_record WHERE DATE_FORMAT(salary_month, '%Y-%m') = DATE_FORMAT(#{salaryMonth}, '%Y-%m')")
    List<SalaryRecord> selectSalaryRecordsByMonth(Date salaryMonth);
}